package com.zzy.mccjt.service.common.config;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

import static springfox.documentation.builders.PathSelectors.regex;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket customDocket() {
        Object a = this.getClass();
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("无需授权")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.any())
                .build();
    }


    @SuppressWarnings("deprecation")
    private ApiInfo apiInfo() {
        Contact contact = new Contact("zzy", "", "13476126718@163.com");
        return new ApiInfoBuilder()
                .title("接口文档")
                .description("文档仅供参考")
                .contact(contact)
                .version("1.0")
                .build();
    }

    /**
     * 设置过滤规则
     * 这里的过滤规则支持正则匹配
     * @return
     */
    private Predicate<String> publicFilteRules() {

        List<String> urls = new ArrayList<>();
        List<Predicate<String>> objs = new ArrayList<>();
        for (String url : urls) {
            objs.add(regex(url));
        }
        return Predicates.or(objs);

        /*return Predicates.or(
                regex("/demo/logTest"),
                regex("/demo/pageSelect")
        );*/
    }

}

